
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Diagnostics;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Security;

namespace Syrinx
{
    /// <summary>
    /// 
    /// </summary>
	public class BaseBizRules : Swaf.BizRule.BaseBizRule
	{
        /// <summary>
        /// 
        /// </summary>
		protected static UserLogin.IUserLoginManager LoginMgr
		{
			get
			{
				return (UserLogin.IUserLoginManager)App.appData.get("sysObjs-UserLogin");
			}
		}
        /// <summary>
        /// 
        /// </summary>
		protected static IBizObj CurrentUser
		{
			get
			{
				Debug.Assert(App.securityMgr.currentPrincipal.additionalInfo != null);
				Debug.Assert(App.securityMgr.currentPrincipal.additionalInfo is IBizObj);
				return (IBizObj)CurrentPrincipal.additionalInfo;
			}
		}
        /// <summary>
        /// 
        /// </summary>
		protected static Swaf.BGuid.Guid CurrentCompanyId
		{
			get
			{
				Debug.Assert(CurrentUser.get("companyId") != null);
				Debug.Assert(CurrentUser.get("companyId") is Swaf.BGuid.Guid);
				return (Swaf.BGuid.Guid)CurrentUser.get("companyId");
			}
		}
        /// <summary>
        /// 
        /// </summary>
		protected static Swaf.BGuid.Guid ActiveCompanyId
		{
			get
			{
				Debug.Assert(CurrentUser.get("activeCompanyId") != null);
				Debug.Assert(CurrentUser.get("activeCompanyId") is Swaf.BGuid.Guid);
				return (Swaf.BGuid.Guid)CurrentUser.get("activeCompanyId");
			}
			set
			{
				CurrentUser.put("activeCompanyId", value);
			}
		}

		protected static IBizObj ActiveCompany
		{
			get
			{
				return App.ruleMgr.execute("getCachedCompanyInfo", ActiveCompanyId).CallResults as IBizObj;
			}
		}
	}
}
